package com.smh.a01MapDemo1;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapDemo2 {
    public static void main(String[] args) {
        Map<Integer,String> map = new HashMap<>();
        map.put(1,"asd");
        map.put(2,"qwe");
        map.put(3,"zxc");
        map.put(4,"fgh");

        System.out.println(map);

        //获取单列key集合(key->value)
        Set<Integer> set = map.keySet();

        for (Integer i : set) {
            System.out.println(map.get(i));
        }
        System.out.println("---------------");

        set.forEach(i->{
            System.out.println(map.get(i));
        });

        System.out.println("---------------");
        Iterator<Integer> it = set.iterator();
        while (it.hasNext()){
            System.out.println(map.get(it.next()));
        }

        System.out.println("-------------");
        System.out.println(map.get(1));

    }
}
